package org.melanesia.converters.jdbc;

import java.sql.Statement;

import org.melanesia.converters.JavaToJdbcConverter;
import org.melanesia.converters.TypeConverter;

/**
 * A simple pass-thru converter that does not convert values, only passes it
 * thru returning specified JDBC Type. This should be used for simple types like
 * String, Integer, Double etc. that can be successfully handled by JDBC without
 * conversion.
 *
 * @author marcin.kielar
 */
public final class PassThruJdbcConverter extends JavaToJdbcConverter {

    /** Holder for the jdbc type that this converter produces. */
    private final int jdbcType;

    /**
     * Constructs a {@link PassThruJdbcConverter}.
     *
     * @param jdbcType
     *            jdbc type produced by this converter
     */
    public PassThruJdbcConverter(final int jdbcType) {
        this.jdbcType = jdbcType;
    }

    @Override
    public Object convert(final TypeConverter typeConverterContext, final Object value, final Statement stmt,
            final String parameterName) {
        return value;
    }

    @Override
    public int getJdbcType(final TypeConverter typeConverterContext) {
        return jdbcType;
    }
}
